﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity;
using SQLite.CodeFirst;

namespace WeManageService
{
    public class WMContext : DbContext
    {
        public WMContext() : base("name = sqlite")
        {

        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Plan>().ToTable("plans").HasKey(p => p.PlanID);
            modelBuilder.Entity<Wish>().ToTable("wishes").HasKey(p=>p.WishID);
            modelBuilder.Entity<User>().ToTable("users").HasKey(p => p.UserName);
            modelBuilder.Entity<Turnover>().ToTable("turnovers").HasKey(p => p.TurnoverID);
            Database.SetInitializer(new SqliteCreateDatabaseIfNotExists<WMContext>(modelBuilder));
        }

        public DbSet<Plan> Plans { get; set; }
        public DbSet<Wish> Wishes { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Turnover> Turnovers { get; set; }
    }
}
